//
// Created by Administrator on 2024/3/11.
//

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<priority_queue<int>> Q(n);
    while (q--) {
        int op, t, x;
        cin >> op >> t;
        if (op == 0) {
            cin >> x;
            Q[t].push(x);
        } else if (op == 1) {
            if (Q[t].empty())continue;
            cout << Q[t].top() << endl;

        } else if (op == 2) {
            if (Q[t].empty())continue;
            Q[t].pop();
        }

    }

    return 0;
}